CREATE  
OR REPLACE PROCEDURE tbch_insert_bsps(p_phid IN NUMBER) 
AS 
    gzxm_phid BIGINT; -- 跟踪项目计划id
    jh_phid BIGINT; -- 跟踪项目信息id
    yzdw_name VARCHAR(255); -- 跟踪计划的业主单位phid
    one_hylb BIGINT; -- 一级行业类别
    tow_hylb BIGINT; -- 二级行业类别
    tbsj_dt DATE;
BEGIN
    -- 查找跟踪项目信息的phid
    SELECT user_bdmc,user_djly INTO gzxm_phid, jh_phid FROM crm3_tend_chk_m where phid = p_phid;
    SELECT u_yzdw,u_hylb,u_ejhylb INTO yzdw_name,one_hylb,tow_hylb FROM p_form_gzxmxx_m where phid = gzxm_phid;

    SELECT user_tbsj INTO tbsj_dt FROM crm3_advance_project where phid = jh_phid;

DBMS_OUTPUT.PUT_LINE('插入失败，错误信息：' || SQLERRM || gzxm_phid || jh_phid || yzdw_name || one_hylb || tow_hylb);
    

    INSERT INTO crm3_tend_file(
        phid,
        phid_org,
        user_yjhylb,
        user_xmmc,
        user_tbjzrq,
        user_tbdw,
        user_sccyllb,
        user_djly,
        phid_pc,
        user_bdmc,
        user_xmms,
        user_ywlb,
        user_scfw,
        user_hylb,
        user_tzje,
        user_sqr,
        tend_dt,
        bill_dt,
        app_status,
        ng_insert_dt,
        ng_update_dt,
        --
        bill_no,
        bill_name,
        phid_pm,
        g_situation,
        remarks,
        phid_schemeid,
        imp_info,
        asr_flag,
        wf_flag,
        arc_flag,
        phid_app,
        level_code,
        print_count,
        bill_type,
        user_type,
        py,
        ng_record_ver,
        creator,
        editor,
        cur_orgid,
        phid_company,
        phid_sourcemid,
        item_resource,
        ng_phid_cu,
        ng_phid_bp,
        ng_phid_ui_scheme,
        ng_phid_original,
        ng_orgid_original,
        ng_sv_search_key,
        ng_sd_search_key,
        ng_share_sign,
        isimport,
        ng_write_source,
        phid_curr,
        ng_phid_org
    )
    SELECT
        seq_auto_phid_sp_org_bb_bsps.nextval,
        phid_org,
        tow_hylb,
        user_xmmc,
        tbsj_dt,
        user_tbdw,
        user_sccyllb,
        p_phid,
        phid_pc,
        user_bdmc,
        user_xmms,
        user_ywlb,
        user_scfw,--市场范围
        NVL(one_hylb,6870000000000679),
        user_tzje,
        user_tbr,
        tend_dt,
        TRUNC(SYSDATE),
        0,
        TRUNC(SYSDATE),
        TRUNC(SYSDATE),
        --
        bill_no,
        '',
        0,
        '',
        '',
        6870000000000038,
        '',
        0,
        null,
        null,
        null,
        0,
        0,
        '',
        '',
        null,
        1,
        0,
        0,
        1,
        0,
        0,
        '',
        1,
        0,
        0,
        0,
        0,
        '10',
        '1',
        5,
        0,
        null,
        null,
        phid_org
    FROM crm3_tend_chk_m
    WHERE phid = p_phid;
    commit;
    EXCEPTION 
    WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('插入失败，错误信息：' || SQLERRM);
    RAISE;
    ROLLBACK;
END tbch_insert_bsps;